public class two {

    public static void main(String[] args) {
        int[] nums = {3, 4, 5, 6, 7, 8};
        int[] nums2 = {5};

        int search = search(nums2, 5);
        System.out.println(search);
    }

    //1,2,3,4,5
    public static int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            int num = nums[mid];
            if (num == target) {
                return mid;
            } else if (num > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return -1;

    }
}
